﻿module lang.d.sts.declarations.denum;

import lang.d.sts.declarations.ddeclaration;
import lang.d.types.dtype;
import lang.d.sts.expressions.dexpression;
import lang.d.types.basictypes;
import lang.d.visitors.dvisitor;

// Identifier expression
class DEnum: DDeclaration {
    private string myName;
    private DType myBaseType;
    private DExpression[string] myMembers;

    public this(uint attribute) {
        super(attribute);
        myBaseType = new IntType();
    }

    public void setName(in string name) {
        myName = name;
    }

    public void setBaseType(DType type) {
        myBaseType = type;
    }

    public DType getBaseType() {
        return myBaseType;
    }

    public void addValue(in string name, DExpression value) {
        myMembers[name] = value;
        value.setParent(this);
    }

    public DExpression opIndex(in string name) {
        if ((name in myMembers) is null) {
            return null;
        }
        return myMembers[name];
    }

    public bool hasName() {
        return myName == string.init;
    }

    override public void accept(DVisitor visitor) {
        visitor.visitEnum(this);
    }
}
